package com.ktjy.utils;

import com.ktjy.entity.SysUser;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserUtils {

    @Autowired
    public  RedisUtils redisUtils;

    public  SysUser getUserByRequest(HttpServletRequest request) {
        String token = request.getHeader("Token");
        if (redisUtils.get(token) != null) {
            return (SysUser) redisUtils.get(token);
        }
        return null;

    }

    public  long getRoleByRequest(HttpServletRequest request) {
        String token = request.getHeader("Token");
        if (redisUtils.get(token) != null) {
            return( (SysUser) redisUtils.get(token)).getUsrRoleId();
        }
        return 0;

    }
}
